pub use colored;

use colored::*;
use termimad::MadSkin;

pub fn print_markdown(md: &str) {
    // Create a "skin" for styling headers, bold, italic
    let mut skin = MadSkin::default();
    skin.bold.set_fg(termimad::crossterm::style::Color::Cyan);
    skin.italic
        .set_fg(termimad::crossterm::style::Color::DarkGrey);

    // Preprocess lines: convert markdown checkboxes into symbols + colors
    let styled_md = md
        .lines()
        .map(|line| {
            let trimmed = line.trim_start();
            if trimmed.starts_with("- [x]") {
                // Done → ● + strikethrough + gray
                let content = trimmed.replacen("- [x]", "●", 1);
                content.strikethrough().bright_black().to_string()
            } else if trimmed.starts_with("- [>]") {
                // Doing → ◐ + green
                let content = trimmed.replacen("- [>]", "◐", 1);
                content.bright_green().to_string()
            } else if trimmed.starts_with("- [ ]") {
                // Undone → ○ + dim gray
                let content = trimmed.replacen("- [ ]", "○", 1);
                content.dimmed().to_string()
            } else {
                line.to_string()
            }
        })
        .collect::<Vec<_>>()
        .join("\n");

    // Render the text using termimad (headers, bold, italic)
    skin.print_text(&styled_md);
}
